<?php

/**
 * This is the model class for table "{{reservation}}".
 *
 * The followings are the available columns in table '{{reservation}}':
 * @property integer $id
 * @property integer $customer_id
 * @property integer $service_id
 * @property string $reservation_date
 * @property string $reservation_time
 * @property string $reservation_type
 * @property string $start_time
 * @property string $end_time
 * @property integer $attendant_id
 * @property integer $bed_id
 * @property string $reservation_status
 * @property string $create_at
 *
 * The followings are the available model relations:
 * @property Customer $customer
 * @property Service $service
 * @property Attendant $attendant
 * @property Bed $bed
 */
class Reservation extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Reservation the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{reservation}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('service_id, reservation_date, reservation_time, reservation_type, start_time, end_time, attendant_id, bed_id, reservation_status', 'required'),
			array('customer_id, service_id, attendant_id, bed_id', 'numerical', 'integerOnly'=>true),
			array('reservation_type', 'length', 'max'=>45),
			array('reservation_status', 'length', 'max'=>20),
			array('create_at', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, customer_id, service_id, reservation_date, reservation_time, reservation_type, start_time, end_time, attendant_id, bed_id, reservation_status, create_at', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'customer' => array(self::BELONGS_TO, 'Customer', 'customer_id'),
			'service' => array(self::BELONGS_TO, 'Service', 'service_id'),
			'attendant' => array(self::BELONGS_TO, 'Attendant', 'attendant_id'),
			'bed' => array(self::BELONGS_TO, 'Bed', 'bed_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'customer_id' => 'Customer Name',
			'customer_id1' => 'Address',
			'customer_id2' => 'Contact Number',
			'service_id' => 'Service',
			'reservation_date' => 'Reservation Date',
			'reservation_time' => 'Reservation Time',
			'reservation_type' => 'Reservation Type',
			'start_time' => 'Start Time',
			'end_time' => 'End Time',
			'attendant_id' => 'Attendant',
			'bed_id' => 'Bed',
			'reservation_status' => 'Reservation Status',
			'create_at' => 'Create At',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('customer_id',$this->customer_id);
		$criteria->compare('service_id',$this->service_id);
		$criteria->compare('reservation_date',$this->reservation_date,true);
		$criteria->compare('reservation_time',$this->reservation_time,true);
		$criteria->compare('reservation_type',$this->reservation_type,true);
		$criteria->compare('start_time',$this->start_time,true);
		$criteria->compare('end_time',$this->end_time,true);
		$criteria->compare('attendant_id',$this->attendant_id);
		$criteria->compare('bed_id',$this->bed_id);
		$criteria->compare('reservation_status',$this->reservation_status,true);
		$criteria->compare('create_at',$this->create_at,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function getFName()
        {       
        return $this->customer['FullName']; 
        }
		
	public function getNo()
		{
		return $this->customer['Contact'];
		}
		
	public function getAdd()
		{
		return $this->customer['Address'];
		}
}